export function add(arg1, arg2) {
  const s1 = arg1.toString();
  const s2 = arg2.toString();
  const arg1Arr = s1.split('.');
  const arg2Arr = s2.split('.');
  const d1 = arg1Arr.length === 2 ? arg1Arr[1] : '';
  const d2 = arg2Arr.length === 2 ? arg2Arr[1] : '';
  const maxLen = Math.max(d1.length, d2.length);
  const m = Math.pow(10, maxLen);
  return Number(((s1 * m + s2 * m) / m).toFixed(maxLen));
}

export function sub(arg1, arg2) {
  return add(arg1, -arg2);
}

export function mul(arg1, arg2) {
  let m = 0;
  const s1 = arg1.toString();
  const s2 = arg2.toString();
  try {
    m += s1.split('.')[1].length;
  } catch (e) { /* */ }
  try {
    m += s2.split('.')[1].length;
  } catch (e) { /* */ }
  return Number(s1.replace('.', '')) * Number(s2.replace('.', '')) / Math.pow(10, m);
}

export function div(arg1, arg2) {
  let t1 = 0;
  let t2 = 0;
  try {
    t1 = arg1.toString().split('.')[1].length;
  } catch (e) { /* */ }
  try {
    t2 = arg2.toString().split('.')[1].length;
  } catch (e) { /* */ }
  const r1 = Number(arg1.toString().replace('.', ''));
  const r2 = Number(arg2.toString().replace('.', ''));
  return (r1 / r2) * Math.pow(10, t2 - t1);
}
